#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define maxn 100100
using namespace std;
int tree[maxn*3];
int lazy[maxn*3];
void build(int rt,int s,int e)
{
	if(s==e)
	{
		tree[rt] = 1;
		return ;
	} 
	else 
	{
		int mid = (s+e)>>1;
		int l_node = rt*2;
		int r_node = rt*2+1;
		build(l_node,s,mid);
		build(r_node,mid+1,e);
		tree[rt]=tree[l_node]+tree[r_node];
	}
}
void update(int rt,int s,int e,int l,int r,int val)
{
//	printf("+++%d %d\n",s,e);

	if(l<=s&&e<=r) 
	{
		
		tree[rt] = val*(e-s+1);
		lazy[rt] = val;
	//	printf("---%d\n",tree[rt]);
		return ;
	}
	int mid =(s+e)>>1;
	int l_node  = rt*2;
	int r_node = rt*2+1;
	if(lazy[rt]&&s!=e)
	{
	//	printf("=======\n");
		lazy[r_node] = lazy[rt];
		tree[r_node] = (e-mid)*lazy[rt];
	//	printf("%d %d\n",l_node,tree[l_node]);
		lazy[l_node] = lazy[rt];
		tree[l_node] = tree[rt]-tree[r_node];
		//printf("%d %d\n",r_node,tree[r_node]);
		lazy[rt] = 0;
	}
	if(l<=mid) update(l_node,s,mid,l,r,val);
	if(r>mid) update(r_node,mid+1,e,l,r,val);
	tree[rt] = tree[l_node]+tree[r_node];
	//printf("tree[%d]=%d\n",rt,tree[rt]);
}
int main()
{
	int t;
	scanf("%d",&t);
	for(int j = 1;j<=t;j++)
	{
		int n,op;
		scanf("%d %d",&n,&op);
		memset(lazy,0,sizeof(lazy));
		build(1,1,n);
		for(int i = 1;i<=op;i++)
		{
		//	printf("****\n");
			int l,r,val;
			scanf(" %d %d %d",&l,&r,&val);
			update(1,1,n,l,r,val);
		}
		printf("Case %d: The total value of the hook is %d.\n",j,tree[1]);
	}
}
